package org.zcode.generator.core.generator;

import org.mybatis.generator.api.GeneratedJavaFile;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.TopLevelClass;
import org.zcode.generator.core.config.BeanTypeConfig;
import org.zcode.generator.core.config.XmlConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 类文件构造器
 * @author zhoulk
 * @date: 2019/10/31
 */
public  abstract class ClazzCreator {

    protected XmlConfig xmlConfig;
    protected BeanTypeConfig beanTypeConfig;
    protected IntrospectedTable introspectedTable;
    protected MethodCreator methodCreator;

    public ClazzCreator(XmlConfig xmlConfig,
                        BeanTypeConfig beanTypeConfig,
                        IntrospectedTable introspectedTable) {
        this.xmlConfig = xmlConfig;
        this.beanTypeConfig = beanTypeConfig;
        this.introspectedTable = introspectedTable;
    }

    /**
     * @Function: org.zcode.generator.core.generator.ClazzCreator.create
     * @Description: 创建文件
     *
     * @param:
     * @return: java.util.List<org.mybatis.generator.api.GeneratedJavaFile>
     *
     * @version: v1.0.0
     * @author: zhoulk
     * @date: 2019/10/31 17:53
     *
     * Modification History:
     * Date             Author      Version            Description
     *---------------------------------------------------------*
     * 2019/10/31 17:53    zhoulk      v1.0.0             修改原因
     *
     */
    public List<GeneratedJavaFile> create() {
        List<GeneratedJavaFile> files = new ArrayList<>();
        GeneratedJavaFile generatedJavaFile = createInterface();
        if (generatedJavaFile!=null) {
            files.add(generatedJavaFile);
        }
        generatedJavaFile = createClazz();
        if (generatedJavaFile!=null) {
            files.add(generatedJavaFile);
        }
        return files;
    }

    /**
     * @Function: org.zcode.generator.core.generator.ClazzCreator.init
     * @Description: 初始化
     *
     * @param:
     * @return: void
     *
     * @version: v1.0.0
     * @author: zhoulk
     * @date: 2019/10/31 17:53
     *
     * Modification History:
     * Date             Author      Version            Description
     *---------------------------------------------------------*
     * 2019/10/31 17:53    zhoulk      v1.0.0             修改原因
     *
     */
    protected abstract void init();

    /**
     * @Function: org.zcode.generator.core.generator.ClazzCreator.createInterface
     * @Description: 创建接口
     *
     * @param:
     * @return: org.mybatis.generator.api.GeneratedJavaFile
     *
     * @version: v1.0.0
     * @author: zhoulk
     * @date: 2019/10/31 17:53
     *
     * Modification History:
     * Date             Author      Version            Description
     *---------------------------------------------------------*
     * 2019/10/31 17:53    zhoulk      v1.0.0             修改原因
     *
     */
    protected abstract GeneratedJavaFile createInterface();

    /**
     * @Function: org.zcode.generator.core.generator.ClazzCreator.createClazz
     * @Description: 创建实现类
     *
     * @param:
     * @return: org.mybatis.generator.api.GeneratedJavaFile
     *
     * @version: v1.0.0
     * @author: zhoulk
     * @date: 2019/10/31 17:52
     *
     * Modification History:
     * Date             Author      Version            Description
     *---------------------------------------------------------*
     * 2019/10/31 17:52    zhoulk      v1.0.0             修改原因
     *
     */
    protected abstract GeneratedJavaFile createClazz();

    /**
     * @Function: org.zcode.generator.core.generator.ClazzCreator.addField
     * @Description: 添加字段
     *
     * @param: topLevelClass
     * @return: void
     *
     * @version: v1.0.0
     * @author: zhoulk
     * @date: 2019/10/31 17:52
     *
     * Modification History:
     * Date             Author      Version            Description
     *---------------------------------------------------------*
     * 2019/10/31 17:52    zhoulk      v1.0.0             修改原因
     *
     */
    protected abstract void addField(TopLevelClass topLevelClass);

    /**
     * @Function: org.zcode.generator.core.generator.ClazzCreator.addImport
     * @Description: 添加导入包
     *
     * @param:
     * @return: void
     *
     * @version: v1.0.0
     * @author: zhoulk
     * @date: 2019/10/31 17:52
     *
     * Modification History:
     * Date             Author      Version            Description
     *---------------------------------------------------------*
     * 2019/10/31 17:52    zhoulk      v1.0.0             修改原因
     *
     */
    protected abstract void addImport();
}
